/*
 * @Author: shiguo
 * @Date: 2021-04-27 10:40:36
 * @LastEditors: shiguo
 * @LastEditTime: 2022-10-28 17:14:14
 * @FilePath: /@aks-dev/easyui/screen/px2sp.ts
 */
import { Dimensions, PixelRatio } from 'react-native';
const pixelRatio = PixelRatio.get();
const width = Dimensions.get('window').width;      //设备的宽度
const height = Dimensions.get('window').height;    //设备的高度

export const px2sp = (size: number) => {

// console.log({
//     pixelRatio,
//     width,
//     height
// })

    if (pixelRatio === 2) {
        // iphone 5s and older Androids
        if (width < 360) {
            return size * 0.95;
        }
        // iphone 5
        if (height < 667) {
            return size;
            // iphone 6-6s
        } else if (height >= 667 && height <= 735) {
            return size * 1.15;
        }
        // older phablets
        return size * 1.25;
    }
    if (pixelRatio === 3) {
        // catch Android font scaling on small machines
        // where pixel ratio / font scale ratio => 3:3
        if (width <= 360) {
            return size;
        }
        // Catch other weird android width sizings
        if (height < 667) {
            return size * 1.15;
            // catch in-between size Androids and scale font up
            // a tad but not too much
        }
        if (height >= 667 && height <= 735) {
            return size * 1.2;
        }
        // catch larger devices
        // ie iphone 6s plus / 7 plus / mi note 等等
        return size * 1.27;
    }
    if (pixelRatio === 3.5) {
        // catch Android font scaling on small machines
        // where pixel ratio / font scale ratio => 3:3
        if (width <= 360) {
            return size;
            // Catch other smaller android height sizings
        }
        if (height < 667) {
            return size * 1.15;//older:1.20
            // catch in-between size Androids and scale font up
            // a tad but not too much
        }
        if (height >= 667 && height <= 735) {
            return size * 1.20;//older:1.25
        }
        // catch larger phablet devices

        return size * 1.25;//older:1.30
    }
    // if older device ie pixelRatio !== 2 || 3 || 3.5
    return size;
};




